package cn.founder.basic.cntroller;

import cn.founder.basic.exception.BusinessException;
import cn.founder.basic.service.IVerifyCodeService;
import cn.founder.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    //发送验证码接口    这里是晓得发来的是字符串才写的String 数据量少可以用map接受
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody Map<String,String> param){
        try {
            //获得前端参数传来的phone 和type类型  区分是绑定验证码和注册验证码
            verifyCodeService.smsCode(param);//根据手机号发送验证码
            return AjaxResult.myself();//发送成功返回消息
        } catch (BusinessException e) {
            //发送失败
            e.printStackTrace();
            return AjaxResult.fail(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail("系统繁忙，请稍后再试。");
        }
    }

}
